package com.jinxin.platform.cdacscontrolmgr.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdacscontrolmgr.service.ICdacscontrolkmgrCarRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-15
 * @Author: Lingnan
 **/
@APCOSApi(value = "车辆记录接口", developers = {"lingnan"}, description = "车辆记录接口")
@RestController
@RequestMapping("/cdacscontrolmgr/cdacscontrolmgrCarRecord")
@Slf4j
public class CdacscontrolmgrCarRecordController {
    @Autowired
    ICdacscontrolkmgrCarRecordService carRecordService;

    @APCOSApiOperation(value = "分页查询车辆记录", developers = {"lingnan"}, description = "分页查询车辆记录",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,
                                   @RequestParam(name = "projectId")String projectId,
                                   @RequestParam(required = false,name = "carNo")String carNo,
                                   @RequestParam(required = false,name = "category")String category,
                                   @RequestParam(required = false,name = "signoName")String signoName,
                                   @RequestParam(required = false,name = "direction")String direction,
                                   @RequestParam(required = false,name = "startDate")String startDate,
                                   @RequestParam(required = false,name = "endDate")String endDate){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","success");
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("projectId", projectId);
        param.put("carNo", carNo);
        param.put("category", category);
        param.put("signoName", signoName);
        param.put("direction", direction);
        param.put("startDate", startDate);
        param.put("endDate", endDate);
        resultMap.put("count", carRecordService.listPageCount(param));
        resultMap.put("data", carRecordService.listPage(param));
        return resultMap;
    }

    @APCOSApiOperation(value = "获取道闸列表", developers = {"lingnan"}, description = "获取道闸列表",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/listBarrierOptions")
    public JsonResult listBarrierOptions(String projectId){
        return JsonResult.ok(carRecordService.listBarrierOptions(projectId));
    }

    @APCOSApiOperation(value = "获取门禁最新的车辆信息", developers = {"lingnan"}, description = "获取门禁最新的车辆信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/queryRecentCarInfo")
    public JsonResult queryRecentCarInfo(@RequestParam(name = "projectId") String projectId,
                                         @RequestParam(name = "mac") String mac){
        return carRecordService.queryRecentCarInfo(projectId,mac);

    }

    @APCOSApiOperation(value = "根据项目id查询车辆类别", developers = {"lingnan"}, description = "根据项目id查询车辆类别",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/listCategory")
    public JsonResult listCategory(@RequestParam(name = "projectId")String projectId){
        return JsonResult.ok(carRecordService.listCategory(projectId));
    }

}
